1. Field of the Invention
The present invention relates to a coding apparatus in which a code amount for length fixing is calculated during variable length coding.
2. Related Background Art
In a conventional method of highly efficiently coding image data, the image data is divided into a small block of i.times.j pixels, a small block is orthogonally transformed, (e.g., two-dimensional discrete cosine transformation (DCT)), the orthogonally transformed coefficients are quantized while considering the human visual sense characteristics, and the quantized coefficients are transformed into a variable length code (e.g., a Huffman code which is a combination of a run length of 0 coefficients and amplitudes of significant coefficients).
In recording variable length coded data in a VTR or the like, k small blocks (k.gtoreq.1, integer) are coded so as to match a record or transmission rate, and the code amount after coding is controlled to be R.sub.K or smaller.
FIG. 1 shows a conventional coding apparatus which performs such a code amount control.
In FIG. 1, reference numeral 1300 represents an input terminal for image data to be orthogonally transformed, reference numerals 1302.sub.0 to 1302.sub.N-1 represent a table number of each quantization table or an input terminal for a quantization step, reference numeral 1304 represents a FIFO for delaying input image data by a time required for determining a quantization table by which the input image data is quantized.
Reference numerals 1306.sub.0 to 1306.sub.N-1 represent a quantization circuit for quantizing orthogonally transformed image data, reference numerals 1308.sub.0 to 1308.sub.N-1 represent a code length generation circuit for generating a code length of image data quantized and variable-length coded, reference numerals 1310.sub.0 to 1310.sub.N-1 represent an adder circuit for adding code lengths, and reference numerals 1312.sub.0 to 1312.sub.N-1 represent a latch circuit for latching a code length added each time a code is generated.
Reference numeral 1314 represents a selection circuit which selects, from N code amounts obtained through variable length coding of k small blocks by N quantization tables, the code amount nearest to a desired amount R.sub.k, and outputs a corresponding quantization table Q.sub.n or its quantization table number n (0.ltoreq.n.ltoreq.N-1) from an output terminal 1318. Reference numeral 1316 represents an output terminal of delayed image data from FIFO 1304.
The operation of the coding apparatus structured as above will be described.
Image data is divided into small blocks. Each small block is orthogonally transformed (e.g., two-dimensional DCT), and the transformed image data is applied to the input terminal 1300. The quantization circuits 1306.sub.0 to 1306.sub.N-1 divide two-dimensionally DCT image data of each small block into M areas in the range from low to high frequencies, for example, as shown in FIG. 2, and quantize at a predetermined step size which becomes coarse from the area 0 to area N-1 toward the high frequency range while considering the human visual sense characteristics, for example, as shown in FIG. 3.
The quantization circuit 1306.sub.0 is supplied with a quantization table Q.sub.0 from the input terminal 1302.sub.0, and quantizes DCTed image data of a small block, at a step size of 1/16 for the area 0, 1/16 for the area 1, . . . , and 1/64 for the area M-1, in accordance with the quantization table Q.sub.0. The image data of the small block quantized by the quantization circuit 1306.sub.0 using the quantization table Q.sub.0 is supplied to the code length generation circuit 1308.sub.0. The code length generation circuit 1308.sub.0 generates a code length of a variable length code suitable for the quantized image data and supplies it to the adder circuit 1310.sub.0. The variable length code is, for example, a two-dimensional Huffman code which is a combination of a run length of 0 values of quantized image data and significant values.
The adder circuit 1310.sub.0 is supplied with a code length from the code length generation circuit 1308.sub.0 and with a cumulative value of past code lengths from the latch circuit 1312.sub.0, and adds the two values, the result being supplied to the latch circuit 1312.sub.0. The latch circuit 1312.sub.0 latches the added value from the adder circuit 1310.sub.0 and supplies it to the adder circuit 1310.sub.0 and also to the selection circuit 1314. The value latched in the latch circuit 1312.sub.0 is reset to "0" each time a set of k small blocks as the length fixing unit has been processed.
Similar to the above, the quantization circuits 1306.sub.1 to 1306.sub.N-1 quantize orthogonally transformed image data by using quantization tables Q.sub.1 to Q.sub.N-1, and the code length generation circuits 1308.sub.1 to 1308.sub.N-1, adder circuits 1310.sub.1 to 1310.sub.N-1, and latch circuits 1312.sub.1 to 1312.sub.N-1 operate in the similar manner as above for the quantized image data. Each latch circuit 1312.sub.1 to 1312.sub.N-1 is reset to "0" at a similar timing in the unit of k small blocks. In this manner, the latch circuit 1312.sub.0 to 1312.sub.N-1 calculate code amounts RQ.sub.0 to RQ.sub.N-1 of codes of the orthogonally transformed k small blocks quantized by using the quantization tables Q.sub.0 to Q.sub.N-1.
The selection circuit 1314 is supplied with N code amounts RQ.sub.0, RQ.sub.1, . . . , RQ.sub.N-1 for each set of k small blocks from the latch circuits 1312.sub.0, 1312.sub.1, . . . , 1312.sub.N-1. The selection circuit 1314 selects, from these N code amounts, the largest RQ.sub.n satisfying R.sub.QN .ltoreq.R.sub.K which is determined to be the code amount of the fixed length code, and outputs a corresponding quantization table Q.sub.n or its quantization table number n (0.ltoreq.n.ltoreq.N-1) from the output terminal 1318. FIFO 1304 delays orthogonally transformed image data by a time required for the selection circuit 1314 to determine the quantization table.
After the quantization table is determined, a circuit (not shown) quantizes the image data delayed by FIFO 1304 by using the determined quantization table Q.sub.n and codes the quantized image data into variable length codes to obtain desired codes.
With the above conventional coding apparatus, however, in order to compress k small blocks into a desired code amount R.sub.K or smaller, N quantization circuits and N code amount calculating circuits corresponding in number to N quantization tables are required. The coding apparatus has therefore a bulky amount of hardware.
Since k small blocks are quantized by using the same quantization table Q.sub.n, the code amount R.sub.QN after length fixing becomes too small depending upon image data, and a difference R.sub.K -R.sub.QN from the target code amount R.sub.K becomes too large. Therefore, an empty area is generated in a record or transmission area, which is not efficient and an image is degraded.